package demo.map;

import java.util.*;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-23
 */
public class Main {
    public static void main(String[] args) {
        Map map = new HashMap();

        map.put("01", "张三");
        map.put("01", "李四");
        map.put("02", "张三");
        map.put("03", "王五");

        //取ketset
        System.out.println("---------keyset---------");
        Set keyset = map.keySet();
        for (Object o : keyset) {
            System.out.println(o + "->" + map.get(o));
        }
        System.out.println("__________-");
        Iterator it = keyset.iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            System.out.println((String)obj + "->" + (String)map.get(obj));
        }

        //取values
        System.out.println("---------values-------");
        Collection set2 = map.values();

        for (Object o : set2) {
            System.out.println(o);
        }
        System.out.println("_____________");
        Iterator it2 = set2.iterator();
        while (it2.hasNext()) {
            Object obj = it2.next();
            System.out.println((String)obj);
        }

        //取entrySet
        System.out.println("--------entry---------") ;
        Set set3 = map.entrySet();

        for (Object o : set3 ) {
            Map.Entry entry = (Map.Entry)o;
            System.out.println(entry.getKey() + "->" + entry.getValue());
        }
        System.out.println("-----------");
        Iterator it3 = set3.iterator();
        while (it3.hasNext()) {
            Map.Entry entry = (Map.Entry)it3.next();
            System.out.println(entry.getKey() + "->" + entry.getValue());
        }

    }
}
